import 'package:flutter/material.dart';
import 'package:flutter1911/page/cart/cart_bottom.dart';
import 'package:flutter1911/page/cart/cart_item.dart';
import 'package:flutter1911/provider/cart_provider.dart';
import 'package:provider/provider.dart';

class CartPage extends StatelessWidget {
  const CartPage({Key? key}) : super(key: key);

  _getCartInfo(context) async {
    await Provider.of<CartProvider>(context, listen: false).getCartInfo();
  }

  @override
  Widget build(BuildContext context) {
    _getCartInfo(context);
    return Scaffold(
      appBar: AppBar(
        title: const Text('购物车'),
      ),
      body: Stack(
        children: [
          ListView.builder(
            itemBuilder: (context, index) {
              return CartItem(
                  item: context.watch<CartProvider>().cartList[index]);
            },
            itemCount: context.watch<CartProvider>().cartList.length,
          ),
          Positioned(
            child: CartBottom(),
            bottom: 0,
            left: 0,
          )
        ],
      ),
    );
  }
}
